//
//  UIBarButtonItem+Extensions.m
//  TWSWeibo
//
//  Created by Twisal on 2017/1/3.
//  Copyright © 2017年 Twisal. All rights reserved.
//

#import "UIBarButtonItem+Extensions.h"

@implementation UIBarButtonItem (Extensions)

+ (instancetype)itemWithTitle:(NSString *)title fontSize:(CGFloat)fontSize target:(id)target action:(SEL)action isBack: (BOOL)isBack {
    UIButton *btn = [UIButton cz_textButton:title fontSize:fontSize normalColor:[UIColor darkGrayColor] highlightedColor:[UIColor orangeColor]];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    if (isBack) {
        NSString *imageName = @"navigationbar_back_withtext";
        [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted", imageName]] forState:UIControlStateHighlighted];
        [btn sizeToFit];
    }
    
    return [[self alloc] initWithCustomView:btn];
}

+ (instancetype)itemWithTitle:(NSString *)title target:(id)target action:(SEL)action isBack: (BOOL)isBack {
    return [self itemWithTitle:title fontSize:16.0 target:target action:action isBack:isBack];
}

+ (instancetype)itemWithTitle:(NSString *)title target:(id)target action:(SEL)action {
    return [self itemWithTitle:title target:target action:action isBack:false];
}
@end
